@extends('layouts.app')

@section('title', translate('购物车'))
@section('content')
@include('common.header', ['title'=> translate('购物车')])
<link rel="stylesheet" type="text/css" href="/fontpage/css/lijigoumai.css">
<style>
        label {
            cursor: pointer;
            display: inline-block;
            font-size:1rem;
            margin-right:0;
            padding-left: 25px;
            position: relative;
            left: 0;
            width:40%;
            line-height: 30px;

        }
        .radio{width: 100% !important;}
        input[type="radio"] {
            display: none;
        }
        label:before {
            background-color:#ff900d;
            bottom: 1px;
            /*box-shadow: 0 2px 3px 0 rgba(0, 0, 0, 0.3) inset, 0 1px 0 0 rgba(255, 255, 255, 0.8);*/
            content: "";
            display: inline-block;
            height: 20px;
            left: 0;
            margin-right: 10px;
            position: absolute;
            top: 5px;
            width: 20px;
        }
        .radio label:before {
            border-radius:100%;
        }
        input[type="radio"]:checked + label:before {
            color: #f3f3f3;
            /*content: "•";*/
            font-size: 30px;
            line-height: 18px;
            text-align: center;
        }
        a.add-btn {
    width: 100%;
    height: 2.425em;
    display: block;
    border-radius: 5px;line-height: 40px; height: 40px;
    text-align: center;
}

    </style>
<section class="aui-address-content">
    <div class="aui-address-box">

            <div class="aui-address-box-list aid" aid="{{isset($address->id)?$address->id:'0'}}">
                @if(isset($address) && !empty($address))
                <a href="{{JpUrl('/user/toAddress?type=1')}}" class="aui-address-box-default">
                    <ul>

                        <li>
                            <strong><div style="color:#2aa8fd;float: left">{{$address->name}}</div>
                                <div style="color:#2aa8fd;float: left"> &nbsp;{{$address->mobile}}</div></strong>
                            @if($address->is_default == 1)
                            <span class="aui-tag aui-tag-default" id="aui-default">{{translate("默认")}}</span>
                            @endif
                        </li>
                        <li>
                            <i class="aui-icon aui-icon-address"></i>
                            {{$address->address}}
                        </li>
                        @else

                    </ul>
                </a>
                <a class="add-btn" href="{{JpUrl('/user/toAddress?type=1')}}">
                    + {{translate("新建收货地址")}}
                </a>
                @endif
            </div>
            <div class="address_defalut address_border"></div>



    </div>
    <div class="aui-dri"></div>
    <div class="aui-list-product-float-item">

        @foreach($List as $row)
            <a href="javascript:;" class="aui-list-product-fl-item goods">
                <input type="hidden" name="goods_attr_id" value="{{$row->id}}">
                <input type="hidden" name="goods_id" value="{{$row->goods_id}}">
                <div class="aui-list-product-fl-img">
                    <img src="{{url('upload/'.$row->goods->thumb)}}" alt="">
                </div>
                <div class="aui-list-product-fl-text">
                    <h3 class="aui-list-product-fl-title">
                        {{translate($row->goods, "title")}}
                    </h3>
                    <h3 class="aui-list-product-fl-title" style="text-align: left;margin-left:24px;width: 60px;">
                        {{translate($row->goods_attr, "name")}}
                    </h3>
                    <div class="aui-list-product-fl-mes">
                        <div>
							<span class="aui-list-product-item-price">
								<span style="color:#999;width:42px;display: inline-block;">{{translate("单价")}}:</span>
								<em style="position: relative;left: -3%;">¥</em>
								<span style="position: relative;left: -6%;"> {{$row->goods_attr->price}}</span>

							</span>
                            <span style="position: relative;left:-7%;font-size: 17px;">x{{$row->number}}</span>
                            <span style="font-size: 17px;position: relative;left:-8%;">{{translate($row->goods_attr, "unit")}}</span>
                        </div>
                    </div>
                </div>
                <div class="sp_zj">¥{{$row->goods_attr->price*$row->number}}</div>
            </a>
        @endforeach



    </div>
    <div class="aui-address-well">
        <a href="#" class="aui-address-cell aui-fl-arrow">
            <div class="aui-address-cell-bd fanshi" style="margin-top: 1%;">{{translate("交易方式")}}:</div>
            <div class="jy_fs">
                <div class="radio">
                    <input type="radio" value="0" name="sex" id="radio1" checked="" class="buyway">
                    <label for="radio1">{{translate("线上交易")}}</label>

                    <input type="radio" value="1" name="sex" id="radio2" class="buyway">
                    <label for="radio2">{{translate("线下交易")}}</label>
                </div>
            </div>
        </a>
        <!-- <div class="aui-prompt">您的商品发货成功后，请您做好收货准备！</div>
        <a href="#" class="aui-address-cell aui-fl-arrow aui-fl-arrow-clear">
            <div class="aui-address-cell-bd">发票</div>
            <div class="aui-address-cell-ft">个人</div>
        </a>
        <!-- <div class="aui-dri"></div>
        <a href="#" class="aui-address-cell aui-fl-arrow aui-fl-arrow-clear">


                <div class="aui-address-cell-bd">无可用积分</div>


                <input type="hidden" class="score" cost="0" style="width: 18px;height: 18px;position: relative;top:.3vh;right: 1%;">
                <span>无优惠</span>


        </a> -->
        <div class="aui-dri"></div>
        <a href="#" class="aui-address-cell aui-fl-arrow aui-fl-arrow-clear">
            <div class="aui-address-cell-bd">{{translate("商品总价")}}</div>
            <div class="aui-address-cell-ft">¥{{$total}}{{translate("元")}}</div>
        </a>
        <!-- <div class="aui-dri"></div>
        <a href="#" class="aui-address-cell aui-fl-arrow aui-fl-arrow-clear">
            <div class="aui-address-cell-bd">其他价格</div>
            <div class="aui-address-cell-ft">¥0.0元</div>
        </a>

        <div class="aui-dri"></div>
         -->









        <!--	<div style="width: 100%;height: 40px;"></div>-->
    </div>
    <div class="aui-payment-bar">
        <div class="shop-total">
            <span class="aui-red aui-size">{{translate("实付款")}}: <em>￥{{$total}}</em></span>
        </div>
        <a class="settlement submit">{{translate("提交订单")}}</a>
    </div>
</section>
<script>
$(function () {
    $(".score.choice").eq(0).click(function () {
        if( $(this).prop("checked") == false )
        {
            $(".score.choice").eq(0).attr("cost",0);
        }
        else
        {
            $(".score.choice").eq(0).attr("cost",1);
        }
        //return
        //$("#ssssss").prop("checked")
    })
})
    $(".submit").click(function () {
        //aid , buyway , cost
        var aid=$(".aid").attr("aid");//aid
        //console.log("aid="+aid);
        var buyway=$(".buyway:checked").val();//buyway
        //console.log("buyway="+buyway);
        var $list=$(".goods");//goods  fid , cid , amount , detail
        //score cost: 0 / 1
        $(".score.choice").click(function () {
            if( $(this).prop("checked") == true )
            {
                $(this).attr("cost",1);
                //$(this).prop("checked",false);
            }
            else if( $(this).prop("checked") == false )
            {
                $(this).attr("cost",0);
            }
        });
        var cost=$(".score").attr("cost");//cost
        //console.log("cost="+cost);
        var json= {};
        json.goods = new Array();
        $list.each(function (i) {

            var fid=$(this).find("input[name='goods_attr_id']").val();
            var cid=$(this).find("input[name='goods_id']").val();
            if(cid==null || cid.length<=0)
            {
                cid="null";
            }
            json.goods[i] = {
                goods_attr_id:fid,
                goods_id:cid
            }
        });
        json.address_id = aid
        json.buyway = buyway

        console.log(json);
        ajaxurl("{{JpUrl('/user/createPay')}}",json,function(data){
        	layer.msg(data.msg)

        	if(data.status==1)
            {
        		setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
    				window.location.href="{{JpUrl('/user/toMyOrder')}}";//页面刷新
    			},2000);
            }

        });


    });

</script>
@endsection
@section('footer')
     @include('common.footer')
@stop
